package org.suburban.data;

import java.util.LinkedList;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.Query;
/**
 * Entity helper class 
 * 
 * @author Alexey Palamarchuk (slonnik@gmail.com)
 *
 */
public class EntityHelper {

	/**
	 * erase all information
	 * @param type	- entity type to be erased
	 */
	public static void clear(String type)
	{
		LinkedList<Key> keys = new LinkedList<Key>();
		DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
		for(Entity entity :datastore.prepare(new Query(type)).asIterable())
		{
			keys.add(entity.getKey());
		}
		datastore.delete(keys);
	}
}
